package com.m3958.firstgwt.server.servlet;

import java.io.IOException;
import java.util.UUID;

import javax.persistence.EntityManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Singleton;
import com.m3958.firstgwt.server.service.AppUtilService;
import com.m3958.firstgwt.server.service.ReqParaService;



@Singleton
public class UuidGeneratorServlet extends HttpServlet{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Inject
	private Injector injector;
	
	@Inject
	private AppUtilService auservice;
	
	
	@Inject
	protected com.google.inject.Provider<EntityManager> emp;

	
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		
		ReqParaService reqps = injector.getInstance(ReqParaService.class);
		
		String uuid = UUID.randomUUID().toString().toLowerCase().replace("-", "");
		if(reqps.isJsonp()){
			auservice.writeJsonpResponse(res, uuid, reqps.getCallbackName());
		}else{
			auservice.writeJsonResponse(res, uuid);
		}
	}

}
